import constantRoutes from './constantRoutes'
import { createRouter, createWebHashHistory, RouteRecordRaw, Router } from "vue-router";

import Layout from "@/layout/index.vue";

// export { permissionRoutes, PermissionRoutes }
// constantRoutes
const routes: Array<RouteRecordRaw> = [
    {
        path: '/:pathMatch(.*)*',
        component: () => import(/* webpackChunkName: "error-page-401" */ '@/views/error-page/404.vue')
    },
    {
        path: '/redirect',
        component: () => Layout,
        meta: { hidden: true },
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import(/* webpackChunkName: "redirect" */ '@/views/redirect/index.vue')
            }
        ]
    },

    {
        path: '/login',
        component: () => import(/* webpackChunkName: "error-page-404" */ '@/views/login/index.vue'),
        name: 'Login',
        meta: {
            title: '用户登录',
            noCache: true
        }
    },
    {
        path: '/404',
        component: () => import(/* webpackChunkName: "error-page-404" */ '@/views/error-page/404.vue'),
        name: 'Page404',
        meta: {
            title: 'page404',
            noCache: true
        }
    },
    ...constantRoutes,

    // {
    //     path: '/401',
    //     component: () => import(/* webpackChunkName: "error-page-401" */ '@/views/error-page/401.vue'),
    //     name: 'Page401',
    //     meta: {
    //         title: 'page401',
    //         noCache: true
    //     }
    // },
];

const router: Router = createRouter({
    history: createWebHashHistory(),
    routes: routes
})

export function resetRouter() {
    const newRouter: Router = router;
    (router as any).matcher = (newRouter as any).matcher // reset router
}

export default router;
